package com.lifeng.springevent.defaultevent;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.ContextStartedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * Created by lifeng on 2019/8/5.
 * ContextClosedEvent 监听Spring容器成功关闭时事件 这个时候会销毁所有的单例bean； 
 * ApplicationContext关闭后触发的事件；
 * （如web容器关闭时自动会触发spring容 器的关闭，如果是普通java应用，需要调用ctx.registerShutdownHook();注册虚拟机关闭时的钩子才行）
 */
@Component
public class MySpringClosedListener implements ApplicationListener<ContextClosedEvent>{
    private static final Logger log = LoggerFactory.getLogger(MySpringClosedListener.class);

	@Override
	public void onApplicationEvent(ContextClosedEvent event) {
		System.out.println("closed...");
	}

}
